package com.zimug.boot.launch.config;

import lombok.extern.slf4j.Slf4j;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;

@Slf4j
//@WebFilter(filterName="customFilter",urlPatterns={"/*"})
public class CustomFilter implements Filter {
  @Override
  public void init(FilterConfig filterConfig) throws ServletException {
    log.info("filter 初始化");
  }

  @Override
  public void doFilter(ServletRequest servletRequest,
                       ServletResponse servletResponse,
                       FilterChain filterChain) throws IOException, ServletException {


    log.info("customFilter 请求处理之前----doFilter方法之前过滤请求");
    servletRequest.setCharacterEncoding("UTF-8");

    filterChain.doFilter(servletRequest, servletResponse);

    servletResponse.setCharacterEncoding("UTF-8");
    log.info("customFilter 请求处理之后----doFilter方法之后处理响应");

  }

  @Override
  public void destroy() {
    log.info("filter 销毁");
  }
}
